package puzzle;

import aima.core.agent.Action;
import aima.core.search.framework.ResultFunction;

public class PuzzleResultFunction implements ResultFunction {

	private static PuzzleResultFunction instance;
	
	private PuzzleResultFunction() {
		
	}
	
	public static PuzzleResultFunction getInstance(){
		if(instance == null) {
			instance = new PuzzleResultFunction();
		}
		
		return instance;
	}
	
	@Override
	public Object result(Object s, Action a) {
		PuzzleBoard current = (PuzzleBoard)s;
		PuzzleBoard result = new PuzzleBoard(current.getBoard().clone());
		
		if(a.equals(PuzzleBoard.C_DER)) {
			result.moverCuadranteCentroDerecha();
		} else if (a.equals(PuzzleBoard.C_IZQ)) {
			result.moverCuadranteCentroIzquierda();
		} else if (a.equals(PuzzleBoard.E_DER)) {
			result.moverCuadranteEsteDerecha();
		} else if (a.equals(PuzzleBoard.E_IZQ)) {
			result.moverCuadranteEsteIzquierda();
		} else if (a.equals(PuzzleBoard.N_DER)) {
			result.moverCuadranteNorteDerecha();
		} else if (a.equals(PuzzleBoard.N_IZQ)) {
			result.moverCuadranteNorteIzquierda();
		} else if (a.equals(PuzzleBoard.O_DER)) {
			result.moverCuadranteOesteDerecha();
		} else if (a.equals(PuzzleBoard.O_IZQ)) {
			result.moverCuadranteOesteIzquierda();
		} else if (a.equals(PuzzleBoard.S_DER)) {
			result.moverCuadranteSurDerecha();
		} else if (a.equals(PuzzleBoard.S_IZQ)) {
			result.moverCuadranteSurIzquierda();
		}
		
		return result;
	}

}
